#include "Compiler.h"
#include "Interpreter.h"

using namespace FlooP;

int main (int argc, const char* argv[])
{
	try
	{
		if (argc == 2) {
			FileInput file (argv[1]);
			Lexer lexer (file);
			Parser parser (lexer);

			std::shared_ptr<AST> ast = parser.parse_program ();
			Environment env = Environment ();

			Compiler::Compile (env, ast);

			Interpreter interpreter (env);
			interpreter.execute ();
		}
	}
	catch (Error& error)
	{
		if (error.line () != 0 && error.character () != 0) {
			std::cout << "Error on line " << error.line () << " around character " << error.character () << " : " << error.error ();
		} else {
			std::cout << error.error ();
		}
	}

	return 0;
}